﻿using System.Collections.Generic;
using Dolany.UtilityTool;
using JetBrains.Annotations;
using Missbot.Core.Base;
using Missbot.Model.MsgInfos;
using Newtonsoft.Json;

namespace Missbot.Core.Channels
{
    [UsedImplicitly]
    public class UrlUploadFinishedChannel : IMsgChannel
    {
        public override string Name => "UrlUploadFinished";
        public override ChannelType BindingType => ChannelType.UrlUploadFinished;
        public override string ChannelFlag => "urlUploadFinished";

        protected override void Send(OutboxDTO dto)
        {
        }

        protected override InboxSession ParseDataImpl(string msg)
        {
            var model = JsonConvert.DeserializeObject<UrlUploadFinishedInfo>(msg);
            if (model?.Body == null)
            {
                return null;
            }

            var body = model.Body;
            return new InboxSession
            {
                SourceID = body.ID,
                Files = new[] { body.Body.File },
                Addition = new Dictionary<string, object> { { "Marker", body.Body.Marker } }.ToSafe()
            };
        }
    }
}